<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>SemOpt: src/AF.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">SemOpt
   &#160;<span id="projectnumber">0.2alpha5-SCC</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('AF_8cpp.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">src/AF.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="AF_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00010"></a>00010 <span class="preprocessor">#include &quot;AF.h&quot;</span>
<a name="l00011"></a>00011 
<a name="l00015"></a><a class="code" href="classAF.html#ad40517371141b07b06a072d3365bb6de">00015</a> <a class="code" href="classAF.html#ad40517371141b07b06a072d3365bb6de" title="Simple constructor.">AF::AF</a>()
<a name="l00016"></a>00016 {
<a name="l00017"></a>00017         <span class="comment">//FIXME valgrind here reports a memory leak of 104 bytes per call. Number of calls: 2</span>
<a name="l00018"></a>00018         this-&gt;arguments = <span class="keyword">new</span> <a class="code" href="classSetArguments.html" title="Class encompassing a set of arguments.">SetArguments</a>();
<a name="l00019"></a>00019         <span class="comment">//this-&gt;raw_attacks = map&lt;int, int &gt;();</span>
<a name="l00020"></a>00020         <span class="comment">//this-&gt;attacks = map&lt;Argument *, SetArguments *&gt;();</span>
<a name="l00021"></a>00021         <span class="comment">//this-&gt;attackers = map&lt;Argument *, SetArguments *&gt;();</span>
<a name="l00022"></a>00022 }
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 AF::~AF()
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027         <span class="comment">// TODO bisogna deallocare il setArguments principale</span>
<a name="l00028"></a>00028 }
<a name="l00029"></a>00029 
<a name="l00036"></a><a class="code" href="classAF.html#a40b85b5c4cb3d96273dd0becacad1a79">00036</a> <span class="keywordtype">bool</span> <a class="code" href="classAF.html#a40b85b5c4cb3d96273dd0becacad1a79" title="Method for parsing a ASPARTIX compliant file.">AF::readFile</a>(<span class="keywordtype">string</span> file)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038         <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a>* newarg;
<a name="l00039"></a>00039         <span class="keywordtype">string</span> inLine;
<a name="l00040"></a>00040         ifstream infile;
<a name="l00041"></a>00041         infile.open(file.c_str());
<a name="l00042"></a>00042         <span class="keywordflow">if</span> (!infile.good())
<a name="l00043"></a>00043                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00044"></a>00044         infile &gt;&gt; inLine;
<a name="l00045"></a>00045 
<a name="l00046"></a>00046         <span class="keywordflow">while</span> (inLine.find(<span class="stringliteral">&quot;arg&quot;</span>) != string::npos &amp;&amp; !infile.eof())
<a name="l00047"></a>00047         {
<a name="l00048"></a>00048                 newarg=<span class="keyword">new</span> <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a>(
<a name="l00049"></a>00049                                 inLine.substr(4, inLine.find_last_of(<span class="stringliteral">&quot;)&quot;</span>) - 4),
<a name="l00050"></a>00050                                 this-&gt;<a class="code" href="classAF.html#a48e30f0573d51a9995093644bb19bb33" title="Returns the number of arguments.">numArgs</a>(),
<a name="l00051"></a>00051                                 this
<a name="l00052"></a>00052                                 );
<a name="l00053"></a>00053                 this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#a989d8986ecf49baa0dc982766c0a5df4" title="Add an argument to the set.">add_Argument</a>(newarg);
<a name="l00054"></a>00054 
<a name="l00055"></a>00055                 infile &gt;&gt; inLine;
<a name="l00056"></a>00056         }
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         <span class="keywordflow">while</span> (!infile.eof())
<a name="l00059"></a>00059         {
<a name="l00060"></a>00060                 <span class="keywordflow">if</span> (inLine.find(<span class="stringliteral">&quot;att&quot;</span>) != string::npos)
<a name="l00061"></a>00061                 {
<a name="l00062"></a>00062                         <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a> *source = this-&gt;<a class="code" href="classAF.html#ab2eccb345f0ebfc6fc2b5cb9f456651b" title="This method returns the pointer to the Argument whose name is given as parameter.">getArgumentByName</a>(
<a name="l00063"></a>00063                                         (inLine.substr(4,
<a name="l00064"></a>00064                                                         inLine.find_last_of(<span class="stringliteral">&quot;,&quot;</span>) - 4)));
<a name="l00065"></a>00065                         <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a> *target = this-&gt;<a class="code" href="classAF.html#ab2eccb345f0ebfc6fc2b5cb9f456651b" title="This method returns the pointer to the Argument whose name is given as parameter.">getArgumentByName</a>(
<a name="l00066"></a>00066                                         (inLine.substr(inLine.find_last_of(<span class="stringliteral">&quot;,&quot;</span>) + 1,
<a name="l00067"></a>00067                                                         inLine.find_last_of(<span class="stringliteral">&quot;)&quot;</span>)
<a name="l00068"></a>00068                                                                         - inLine.find_last_of(<span class="stringliteral">&quot;,&quot;</span>)
<a name="l00069"></a>00069                                                                         - 1)));
<a name="l00070"></a>00070 
<a name="l00071"></a>00071                         source-&gt;<a class="code" href="classArgument.html#a8a5cddf583929099b8228ed9300e2759" title="Method for adding an attacks originated from this argument.">add_attacks</a>(target);
<a name="l00072"></a>00072                         target-&gt;add_attackers(source);
<a name="l00073"></a>00073 <span class="comment">//                      this-&gt;raw_attacks.push_back(</span>
<a name="l00074"></a>00074 <span class="comment">//                                      pair&lt;int, int&gt;(</span>
<a name="l00075"></a>00075 <span class="comment">//                                                      this-&gt;argNameToCode(</span>
<a name="l00076"></a>00076 <span class="comment">//                                                                      (inLine.substr(4,</span>
<a name="l00077"></a>00077 <span class="comment">//                                                                                      inLine.find_last_of(&quot;,&quot;) - 4))),</span>
<a name="l00078"></a>00078 <span class="comment">//                                                      this-&gt;argNameToCode(</span>
<a name="l00079"></a>00079 <span class="comment">//                                                                      (inLine.substr(inLine.find_last_of(&quot;,&quot;) + 1,</span>
<a name="l00080"></a>00080 <span class="comment">//                                                                                      inLine.find_last_of(&quot;)&quot;)</span>
<a name="l00081"></a>00081 <span class="comment">//                                                                                                      - inLine.find_last_of(&quot;,&quot;)</span>
<a name="l00082"></a>00082 <span class="comment">//                                                                                                      - 1)))));</span>
<a name="l00083"></a>00083                 }
<a name="l00084"></a>00084                 infile &gt;&gt; inLine;
<a name="l00085"></a>00085         }
<a name="l00086"></a>00086         infile.close();
<a name="l00087"></a>00087         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00095"></a><a class="code" href="classAF.html#ab2eccb345f0ebfc6fc2b5cb9f456651b">00095</a> <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a> *<a class="code" href="classAF.html#ab2eccb345f0ebfc6fc2b5cb9f456651b" title="This method returns the pointer to the Argument whose name is given as parameter.">AF::getArgumentByName</a>(<span class="keywordtype">string</span> name)
<a name="l00096"></a>00096 {
<a name="l00097"></a>00097         <span class="keywordflow">return</span> this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#ab4ddcd0942b0fa06de4ab9726e12edef" title="This method returns the pointer to the Argument whose name is given as parameter.">getArgumentByName</a>(name);
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00104"></a><a class="code" href="classAF.html#a48e30f0573d51a9995093644bb19bb33">00104</a> <span class="keywordtype">int</span> <a class="code" href="classAF.html#a48e30f0573d51a9995093644bb19bb33" title="Returns the number of arguments.">AF::numArgs</a>()
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106         <span class="keywordflow">return</span> this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#a66d5b1cc6b684700c2394a8cf62ef7f0" title="Retuns the cardinality of this set.">cardinality</a>();
<a name="l00107"></a>00107 }
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 
<a name="l00115"></a><a class="code" href="classAF.html#a370edb6cf152935b65e848d1ae209546">00115</a> <a class="code" href="classArgument.html" title="Class representing an Argument.">Argument</a> *<a class="code" href="classAF.html#a370edb6cf152935b65e848d1ae209546" title="This method returns the pointer to the Argument whose identification number is given as parameter...">AF::getArgumentByNumber</a>(<span class="keywordtype">int</span> num)
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117         <span class="keywordflow">return</span> this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#a119cb47c6e77b8faf10135d90c5b68b9" title="This method returns the pointer to the Argument whose identification number is given as parameter...">getArgumentByNumber</a>(num);
<a name="l00118"></a>00118 }
<a name="l00119"></a>00119 
<a name="l00124"></a><a class="code" href="classAF.html#ab5db00d34fb90c9dd41272fd8953a5b4">00124</a> <a class="code" href="classSetArgumentsIterator.html" title="Class defining a const iterator for the elements of a set of arguments.">SetArgumentsIterator</a> <a class="code" href="classAF.html#ab5db00d34fb90c9dd41272fd8953a5b4" title="Begin of the iterator for the set of arguments.">AF::begin</a>()
<a name="l00125"></a>00125 {
<a name="l00126"></a>00126         <span class="keywordflow">return</span> this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#aaee058feaed861edf27739fa04f374ef" title="Begin of the iterator for this set of arguments.">begin</a>();
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00133"></a><a class="code" href="classAF.html#afc7210c999f6af6172e06b984b13ad1a">00133</a> <a class="code" href="classSetArgumentsIterator.html" title="Class defining a const iterator for the elements of a set of arguments.">SetArgumentsIterator</a> <a class="code" href="classAF.html#afc7210c999f6af6172e06b984b13ad1a" title="End of the iterator for the set of arguments.">AF::end</a>()
<a name="l00134"></a>00134 {
<a name="l00135"></a>00135         <span class="keywordflow">return</span> this-&gt;arguments-&gt;<a class="code" href="classSetArguments.html#a551272d71c803f64efc155b04f41e775" title="End of the iterator for this set of arguments.">end</a>();
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 
<a name="l00147"></a><a class="code" href="classAF.html#aec0b31f7ddc1405309ebc12644c5c3b5">00147</a> <a class="code" href="classSetArguments.html" title="Class encompassing a set of arguments.">SetArguments</a>* <a class="code" href="classAF.html#aec0b31f7ddc1405309ebc12644c5c3b5" title="Return a pointer to the set of arguments.">AF::get_arguments_copy</a>(){
<a name="l00148"></a>00148         <a class="code" href="classSetArguments.html" title="Class encompassing a set of arguments.">SetArguments</a>* result=<span class="keyword">new</span> <a class="code" href="classSetArguments.html" title="Class encompassing a set of arguments.">SetArguments</a>();
<a name="l00149"></a>00149         this-&gt;<a class="code" href="classAF.html#ac415a440c526e9a06a938544503fe741" title="Returns a pointer to the set of arguments.">get_arguments</a>()-&gt;<a class="code" href="classSetArguments.html#a3a3052b05dff877886f84ab99280d6f7" title="Clone this set.">clone</a>(result);
<a name="l00150"></a>00150         <span class="keywordflow">return</span> result;
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 
<a name="l00171"></a><a class="code" href="classAF.html#ac415a440c526e9a06a938544503fe741">00171</a> <a class="code" href="classSetArguments.html" title="Class encompassing a set of arguments.">SetArguments</a> *<a class="code" href="classAF.html#ac415a440c526e9a06a938544503fe741" title="Returns a pointer to the set of arguments.">AF::get_arguments</a>()<span class="keyword"> const</span>
<a name="l00172"></a>00172 <span class="keyword"></span>{
<a name="l00173"></a>00173         <span class="keywordflow">return</span> this-&gt;arguments;
<a name="l00174"></a>00174 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="AF_8cpp.html">AF.cpp</a>      </li>

    <li class="footer">Generated on Fri Jan 17 2014 11:47:51 for SemOpt by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
